<template>
  <AutoLayout v-if="init" :routes="routes" :menu-width="menuWidth" :projectOption="projectOption"/>
</template>

<script>
import AutoLayout from "@/components/AutoLayout/index.vue";
import route from "@/router/customRouter/router-admin.js";
import api from "@/api/index.js";
import {useUserInfoStore} from "@/stores/userInfo.js";

export default {
  name: "index.vue",
  components: {
    AutoLayout
  },
  data() {
    return {
      init: false,
      routes: route,
      menuWidth: 300,
      projectOption: {
        hiddenHeader: true,
        hiddenTag: true,
      }
    }
  },
  mounted() {
    this.getStateToUser();
  },
  methods: {
    async getStateToUser() {
      try {
        let state = localStorage.getItem("token");
        // let state = "8481ed840fbb447ab2b8bf8d954f9da7";
        localStorage.setItem("token", state);
        console.log("state", state);
        if (!state) {
          this.$router.replace("/login");
          return;
        }
        let result = await api.getStateToUser({
          state: state
        });
        let userInfoStore = useUserInfoStore();
        userInfoStore.setUserInfo(result);
        this.init = true;
      } catch (e) {
        console.error(e);
      }
    },
  }
}
</script>

<style scoped>

</style>